<template>
  <div>
    <el-dialog title="会员编辑" :visible.sync="info.isshow" @close="close">
      <el-form :model="user">
        {{ user }}
        <el-form-item label="手机号" label-width="120px">
          <el-input v-model="user.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="昵称" label-width="120px">
          <el-input v-model="user.nickname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" label-width="120px">
          <el-input v-model="user.password" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="状态" label-width="120px">
          <el-switch
            v-model="user.status"
            :active-value="1"
            :inactive-value="2"
          >
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="update">修 改</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { reqmemberedit,reqmemberinfo } from "../../../http/api";
import { successAlert } from "../../../utils/alert";

export default {
  // 接收info
  props: ["info", "arr"],
  data() {
    // 5.1初始化表单的数据
    return {
      user: {
        uid: "",
        nickname: "",
        phone: "",
        password: "",
        status:1,
      },
    };
  },
  computed: {
    ...mapGetters({}),
  },
  mounted() {},
  methods: {
    ...mapActions({}),
    // 8.点了取消
    cancel() {
      this.info.isshow = false;
    },
    // 清空弹窗的方法
    clearUser() {
      this.user = {
       uid: "",
        nickname: "",
        phone: "",
        password: "",
        status: 1,
      };
    },
   
   
    // 8.编辑逻辑
    getOne(uid) {
      // console.log("发请求"+id);
      reqmemberinfo({ uid: uid }).then((res) => {
        if (res.data.code == 200) {
          this.user = res.data.list;
          // 补id
          this.user.id = uid;
        }
      });
    },
    // 9.修改
    update() {
      reqmemberedit(this.user).then((res) => {
        if (res.data.code == 200) {
          // ①弹成功
          successAlert(res.data.msg);
          // ②弹框内容清空
          this.clearUser();
          // ③弹框消失
          this.info.isshow = false;
          // ④重新请求列表
          this.$emit("init");
        }
      });
    },
    // 10.关闭弹框
    close() {
      if (!this.info.isAdd) {
        this.clearUser();
      }
    },
  },
};
</script>
<style scoped lang="less">
@import "../../../less/index.less";
</style>